#include "stackplatesettingwid.h"
#include "ui_stackplatesettingwid.h"
#include "../component/componentmanager.h"

StackPlateSettingWid::StackPlateSettingWid(QWidget* parent)
	: QWidget(parent)
	, ui(new Ui::StackPlateSettingWid())
{
	ui->setupUi(this);
	setStyleSheet("font: 12pt \"Agency FB\"");
	QHBoxLayout* lay = new QHBoxLayout(ui->groupBox);
	m_base = new PositionSettingWid(this);
	lay->addWidget(m_base);

	auto algm = component->GetComponent(Component::component_algorithm);
	if (algm) {
		QByteArray input, output;
		if (algm->ExcuteCmd(1, input, output)) {
			QString name = output;
			QStringList names = name.split('-');
			ui->comboBox->clear();
			ui->comboBox->addItems(names);
		}
	}
}

StackPlateSettingWid::~StackPlateSettingWid()
{
	delete ui;
}


void StackPlateSettingWid::Init(const StackPlateCfg& cfg)
{
	ui->lineEdit->setText(cfg.id());
	ui->spinBox_4->setValue(cfg.di());
	ui->comboBox->setCurrentText(cfg.alg());
	m_base->Init(cfg.base());
	ui->spinBox->setValue(cfg.maxsize().length());
	ui->spinBox_2->setValue(cfg.maxsize().width());
	ui->spinBox_3->setValue(cfg.maxsize().height());
	ui->comboBox_2->setCurrentIndex(cfg.dirOdd());
	ui->comboBox_3->setCurrentIndex(cfg.dirEven());
}
StackPlateCfg StackPlateSettingWid::GetCfg()
{
	StackPlateCfg cfg = {};
	cfg.id() = ui->lineEdit->text();
	cfg.di() = ui->spinBox_4->value();
	cfg.alg() = ui->comboBox->currentText();
	cfg.base() = m_base->GetPositon();
	cfg.dirOdd() = ui->comboBox_2->currentIndex();
	cfg.dirEven() = ui->comboBox_3->currentIndex();
	cfg.maxsize().length() = ui->spinBox->value();
	cfg.maxsize().width() = ui->spinBox_2->value();
	cfg.maxsize().height() = ui->spinBox_3->value();

	return cfg;
}
